const MAX = 20;
const SeqList = {
  arr: new Int8Array(MAX), // 定长数组
};

// 顺序表的插入操作
const addSeqList = (value, index) => {
  if (index < 0 || index > MAX) {
    console.log("index 不能小于0或者大于数组长度");
    return false;
  }
  for (let i = SeqList.arr.length; i > index; i--) {
    SeqList.arr[i] = SeqList.arr[i - 1];
  }
  SeqList.arr[index] = value;
};

// 顺序表的头插尾插基本上是一样的

// 顺序表的删除操作
const delSeqList = (index) => {
  if (index < 0 || index >= MAX) {
    console.log("index 不能小于0或者大于数组长度");
    return false;
  }
  for (let i = index; i < SeqList.arr.length - 1; i++) {
    SeqList.arr[i] = SeqList.arr[i + 1];
  }
};

// 顺序表的查找操作
const findSeqList = (value) => {
  for (let i = 0; i < SeqList.arr.length; i++) {
    if (SeqList.arr[i] === value) {
      return i;
    }
  }
};
addSeqList(1, 0);
addSeqList(2, 0);
addSeqList(2, 21);
addSeqList(23, 3);
console.log(findSeqList(23));
console.log(SeqList.arr);
